<?
if($date){

$txt[check_title] = translate('check_title');
$txt[check_txt1] =  translate('check_txt1');
$txt[check_txt2] =  translate('check_txt2');
$txt[check_txt3] = translate('check_txt3'); 
$txt[check_txt4] = translate('check_txt4'); 
$txt[check_txt5] = translate('check_txt5'); 
$txt[paypal_title] = translate('paypal_title');
$txt[paypal_txt1] = translate('paypal_txt1');
$txt[paypal_txt2] = translate('paypal_txt2');
$txt[paypal_txt3] = translate('paypal_txt3');
$txt[paypal_txt4] = translate('paypal_txt4');
$txt[paypal_txt5] = translate('paypal_txt5');
$txt[paypal_txt6] = translate('paypal_txt6');
$txt[not_faund] = translate('not_faund');

$txt = base64_encode(serialize($txt));
$url="https://payments.duoservers.com/payments/ph_details.php?reseller_id=$id&approved_date=$date&txt=$txt";
//echo $url;
include($url);
}
$sales = list_reseller_sales($id,$period_date);
if(is_array($sales)){

	//Comentarite mahat sabiraneto na nqkolko sale-a s edin i sasht 
	//$s[client]_$s[type]_$s[sale_data]_$s[state] da badat sabirani kato broika i pokazvani zaedno
	//-------------------------------------------------------------------------------------------------

	echo "<br><br><table class=bTable cellspacing=0>
		<tr>	
			<th>".translate('client')."</th>
			<th>".translate('details')."</th>
			<th>".translate('status')."</th>";
	echo 		"<th>".translate('quantity')."</th>";
	echo 		"<th>".translate('wholesale')."</th>
			<th>".translate('retail')."</th>
			<th>".translate('paid')."</th>
		";
	$amount = 0;
	foreach($sales as $s){
		if($s[state]=='normal'){
		$total_wholesale +=$s[real_price];
		$total_revenue +=$s[price];
			
		}else {
			$total_wholesale_ref +=$s[real_price];
			$total_revenue_ref +=$s[price];
		}
		if($s[payed]== 'true') $s[payed]='paid';
		else $s[payed]='not paid';
		if($s[ref_payed]== 'true') $s[ref_payed]='paid';
		else $s[ref_payed]='not paid';
		$cur = "$s[client]_$s[type]_$s[sale_data]_$s[state]";
		if($cur && $cur == $last){
			$amount ++;
		}else {
			$amount++;
			if($row1 && $row2) echo $row1.$amount.$row2;		
			$row1='';
			$row2='';

			$row1 .="<tr>";
			$row1 .="<td>$s[client]</td>";
			$row1 .="<td>
				<b>".translate('date').":</b> $s[date]<br>
				<b>".translate('type').":</b> $s[type]<br>
				<b>".translate('data').":</b> $s[sale_data]
				</td>";
			$row1 .="<td>".(($s[state]!='normal')?"<font color=red>$s[state]</font>":$s[state])."</td>";
			$row1 .="<td align=center>";
			$row2 .="</td>";
			$row2 .="<td align=center>$s[real_price]</td>";
			$row2 .="<td align=center>$s[price]</td>";
			$row2 .="<td align=center>".(($s[link_type]=='union')?(($s[payment_date])?"$s[payed]<br>($s[payment_date])":"$s[payed]"):((affiliate)?"$s[ref_payed]":"$s[ref_payed]"))."</td>";
			$row2 .="</tr>";
			$last = $cur;
			$amount = 0;
		}

	}
	$amount++;
	if($row1 && $row2) echo $row1.$amount.$row2;
	setlocale(LC_MONETARY, 'en_US');
	echo "<tr><td colspan=4 align=right><b>".translate('total_normal').":</b></td><td>".money_format('%i', $total_wholesale)."</td><td>".money_format('%i', $total_revenue)."</td><td>&nbsp;</td></tr>";
	echo "<tr><td colspan=4 align=right><b>".translate('total_refund').":</b></td><td><font color=red>-".money_format('%i',$total_wholesale_ref)."</font></td><td><font color=red>-".money_format('%i',$total_revenue_ref)."</font></td><td>&nbsp;</td></tr>";
}else {
	echo "<br><br>".translate('no_sales');
}
?>
